﻿using Common.Device.ViewModels;
using Common.Tool.DataTools;
using Common.Tool.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common.Device.Models
{
    public abstract class Device
    {
        public double? 下限值 { get; set; }
        public double? 上限值 { get; set; }
        public double? 下限值1 { get; set; }
        public double? 上限值1 { get; set; }
        /// <summary>
        /// 获取上下限显示 min~max unit
        /// </summary>
        /// <param name="unity">单位</param>
        /// <returns></returns>
        protected string GetRange(string unity)
        {
            if (下限值 == null && 上限值 == null)
            {
                return "无";
            }
            else if (下限值 == null && 上限值 != null)
            {
                return "≤" + DataConvert.ToUnit(上限值, "F3") + unity;
            }
            else if (下限值 != null && 上限值 == null)
            {
                return "≥" + DataConvert.ToUnit(下限值, "F3") + unity;
            }
            else if (下限值 != null && 上限值 != null)
            {
                return DataConvert.ToUnit(下限值, "F3") + "~" + DataConvert.ToUnit(上限值, "F3") + unity;
            }
            return null;
        }
        protected string GetRange1(string unity)
        {
            if (下限值1 == null && 上限值1 == null)
            {
                return "无";
            }
            else if (下限值1 == null && 上限值1 != null)
            {
                return "≤" + DataConvert.ToUnit(上限值1, "F3") + unity;
            }
            else if (下限值1 != null && 上限值1 == null)
            {
                return "≥" + DataConvert.ToUnit(下限值1, "F3") + unity;
            }
            else if (下限值1 != null && 上限值1 != null)
            {
                return DataConvert.ToUnit(下限值1, "F3") + "~" + DataConvert.ToUnit(上限值1, "F3") + unity;
            }
            return null;
        }
        /// <summary>
        /// 获取测试指令
        /// </summary>
        /// <param name="deviceName">仪器名</param>
        /// <returns></returns>
        public abstract Order GetOrder(string deviceName);
        /// <summary>
        /// 测试并返回测试结果
        /// </summary>
        /// <param name="dev">仪器实体</param>
        /// <param name="testOrder">测试项指令</param>
        /// <returns></returns>
        public abstract DeviceResult GetResult(object dev, TestOrder testOrder);
        /// <summary>
        /// 检查上下限是否正确
        /// </summary>
        /// <returns></returns>
        public bool MinMaxCheck()
        {
            return (下限值 ?? double.MinValue) <= (上限值 ?? double.MaxValue);
        }
        public bool MinMaxCheck1()
        {
            return (下限值1 ?? double.MinValue) <= (上限值1 ?? double.MaxValue);
        }
    }
}
